{% macro form_field(field, autofocus) %}
  {%- if field.type == 'BooleanField' %}
  <div class="form-check mb-3">
    {{ field(class='form-check-input') }}
    {{ field.label(class='form-check-label') }}
  </div>
  {%- elif field.type == 'RadioField' %}
    {{ field.label(class='form-label') }}
    {%- for item in field %}
    <div class="form-check{% if loop.last %} mb-3{% endif %}">
      {{ item(class='form-check-input') }}
      {{ item.label(class='form-check-label') }}
    </div>
    {%- endfor %}
  {%- elif field.type == 'SelectField' %}
    {{ field.label(class='form-label') }}
    {{ field(class='form-select mb-3') }}
  {%- elif field.type == 'TextAreaField' %}
  <div class="mb-3">
    {{ field.label(class='form-label') }}
    {% if autofocus %}
      {{ field(class='form-control' + (' is-invalid' if field.errors else ''), autofocus=True) }}
    {% else %}
      {{ field(class='form-control' + (' is-invalid' if field.errors else '')) }}
    {% endif %}
    {%- for error in field.errors %}
    <div class="invalid-feedback">{{ error }}</div>
    {%- endfor %}
  </div>
  {%- elif field.type == 'SubmitField' %}
  {{ field(class='btn btn-primary mb-3') }}
  {%- else %}
  <div class="mb-3">
    {{ field.label(class='form-label') }}
    {% if autofocus %}
      {{ field(class='form-control' + (' is-invalid' if field.errors else ''), autofocus=True) }}
    {% else %}
      {{ field(class='form-control' + (' is-invalid' if field.errors else '')) }}
    {% endif %}
    {%- for error in field.errors %}
    <div class="invalid-feedback">{{ error }}</div>
    {%- endfor %}
  </div>
  {%- endif %}
{% endmacro %}

{% macro quick_form(form, action="", method="post", id="", novalidate=False) %}
<form
  {%- if action != None %} action="{{ action }}"{% endif -%}
  {%- if method %} method="{{ method }}"{% endif %}
  {%- if id %} id="{{ id }}"{% endif -%}
  {%- if novalidate %} novalidate{% endif -%}>
  {{ form.hidden_tag() }}
  {%- for field, errors in form.errors.items() %}
    {%- if form[field].widget.input_type == 'hidden' %}
      {%- for error in errors %}
      <div class="invalid-feedback">{{ error }}</div>
      {%- endfor %}
    {%- endif %}
  {%- endfor %}

  {% set ns = namespace(first_field=true) %}
  {%- for field in form %}
    {% if field.widget.input_type != 'hidden' -%}
      {{ form_field(field, ns.first_field) }}
      {% set ns.first_field = false %}
    {%- endif %}
  {%- endfor %}  
</form>
{% endmacro %}
